package com.hxc.web.controller.interest;

import java.util.List;

import com.hxc.common.constant.HttpStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hxc.common.annotation.Log;
import com.hxc.common.core.controller.BaseController;
import com.hxc.common.core.domain.AjaxResult;
import com.hxc.common.enums.BusinessType;
import com.hxc.interest.domain.TSummaryInfo;
import com.hxc.interest.service.ITSummaryInfoService;
import com.hxc.common.utils.poi.ExcelUtil;
import com.hxc.common.core.page.TableDataInfo;

/**
 * 乡村简介Controller
 * 
 * @author hxc
 * @date 2021-08-20
 */
@Api(tags = "乡村介绍管理")
@RestController
@RequestMapping("/interest/summary")
public class TSummaryInfoController extends BaseController
{
    @Autowired
    private ITSummaryInfoService tSummaryInfoService;

    /**
     * 查询乡村简介列表
     */
    @PreAuthorize("@ss.hasPermi('interest:summary:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSummaryInfo tSummaryInfo)
    {
        startPage();
        List<TSummaryInfo> list = tSummaryInfoService.selectTSummaryInfoList(tSummaryInfo);
        return getDataTable(list);
    }

    /**
     * 导出乡村简介列表
     */
    @PreAuthorize("@ss.hasPermi('interest:summary:export')")
    @Log(title = "乡村简介", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSummaryInfo tSummaryInfo)
    {
        List<TSummaryInfo> list = tSummaryInfoService.selectTSummaryInfoList(tSummaryInfo);
        ExcelUtil<TSummaryInfo> util = new ExcelUtil<TSummaryInfo>(TSummaryInfo.class);
        return util.exportExcel(list, "乡村简介数据");
    }

    /**
     * 获取乡村简介详细信息
     */
    @PreAuthorize("@ss.hasPermi('interest:summary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tSummaryInfoService.selectTSummaryInfoById(id));
    }

    /**
     * 新增乡村简介
     */
    @PreAuthorize("@ss.hasPermi('interest:summary:add')")
    @Log(title = "乡村简介", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSummaryInfo tSummaryInfo)
    {
        return toAjax(tSummaryInfoService.insertTSummaryInfo(tSummaryInfo));
    }

    /**
     * 修改乡村简介
     */
    @PreAuthorize("@ss.hasPermi('interest:summary:edit')")
    @Log(title = "乡村简介", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSummaryInfo tSummaryInfo)
    {
        return toAjax(tSummaryInfoService.updateTSummaryInfo(tSummaryInfo));
    }

    /**
     * 删除乡村简介
     */
    @PreAuthorize("@ss.hasPermi('interest:summary:remove')")
    @Log(title = "乡村简介", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSummaryInfoService.deleteTSummaryInfoByIds(ids));
    }

    @ApiOperation(value = "根据类型查询最新的一条数据", notes = "查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "summaryType", value = "简介类型", dataType = "Integer")
    })
    @GetMapping("/querySummaryByType")
    public AjaxResult querySummaryByType(Integer summaryType){
        if(summaryType == null){
            return AjaxResult.error(HttpStatus.BAD_REQUEST,"请求参数不合法");
        }
        return tSummaryInfoService.querySummaryByType(summaryType);
    }

}
